package com.spring.common.allocation;

import org.apache.log4j.Logger;

import com.alibaba.druid.pool.DruidDataSource;
import com.spring.util.EncryptionDecryption;


/**
 * 实现DruidDataSource接口,对用户名和密码进行加密
 * Created by liuyang on 2016/9/21.
 */
public class HxqDruidDataSource extends DruidDataSource {
    /**
	 * 
	 */
	private static final long serialVersionUID = -2286529917030716880L;

	protected final static Logger logger = Logger.getLogger(HxqDruidDataSource.class);

    private String username;

    private String password;

    private static EncryptionDecryption des = EncryptionDecryption.getInstance();

    private HxqDruidDataSource(){}

    private static HxqDruidDataSource hxqDruidDataSource = new HxqDruidDataSource();

    public static HxqDruidDataSource getInstance() {
        return hxqDruidDataSource;
    }


    @Override
    public void setUsername(String username) {
        try {
            this.username = des.decrypt(username);
            super.setUsername(username);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void setPassword(String password) {
        try {
            this.password = des.decrypt(password);
            super.setPassword(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public String getPassword() {
        return password;
    }
}
